package com.huatai.datacenter.controller.datamodel;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.huatai.common.api.R;
import com.huatai.datacenter.entity.datamodel.DataModelEntity;
import com.huatai.datacenter.service.DataModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author gusiyi
 * @version 1.0
 * @className DataModelController
 * @description 描述：数据模型controller
 * @date 2023/5/25 17:27
 */
@RestController
@RequestMapping("/dataModel/data")
@Api(value = "数据模型模块",tags = "数据模型")
public class DataModelController {

	@Autowired
	private DataModelService dataModelService;


	@RequestMapping("/getList")
	@ApiOperation("获取数据模型清册")
	@ApiOperationSupport(order = 1, includeParameters = {
		"dataModelEntity.pageIndex",
		"dataModelEntity.pageSize",
		"dataModelEntity.dataModelName",
		"dataModelEntity.dataModelTypeId"
	})
	public R<Page<DataModelEntity>> getList(@RequestBody DataModelEntity dataModelEntity){
		Page<DataModelEntity> dataModelEntityPage = dataModelService.selectDataModelList(dataModelEntity);
		return R.data(dataModelEntityPage,"获取数据模型成功");
	}

	@RequestMapping("/saveOne")
	@ApiOperation("保存数据模型")
	@ApiOperationSupport(order = 2, includeParameters = {
		"dataModelEntity.dataModelName",
		"dataModelEntity.dataModelTypeId",
		"dataModelEntity.dataModelTypeName",
		"dataModelEntity.remark",
		"dataModelEntity.fields.fieldName",
		"dataModelEntity.fields.fieldCnName",
		"dataModelEntity.fields.fieldType",
		"dataModelEntity.fields.fieldTypeNum",
		"dataModelEntity.examples"
	})
	public R<DataModelEntity> saveOne(@RequestBody DataModelEntity dataModelEntity){
		return R.status(dataModelService.insertDataModel(dataModelEntity));
	}

	@RequestMapping("/updateById")
	@ApiOperation("修改数据模型")
	@ApiOperationSupport(order = 3, includeParameters = {
		"dataModelEntity.id",
		"dataModelEntity.dataModelName",
		"dataModelEntity.dataModelTypeId",
		"dataModelEntity.dataModelTypeName",
		"dataModelEntity.remark",
		"dataModelEntity.fields.id",
		"dataModelEntity.fields.fieldName",
		"dataModelEntity.fields.fieldCnName",
		"dataModelEntity.fields.fieldType",
		"dataModelEntity.fields.fieldTypeNum",
		"dataModelEntity.examples"
	})
	public R<DataModelEntity> updateById(@Valid @RequestBody DataModelEntity dataModelEntity){
		dataModelEntity.setUpdateTime(null);
		dataModelEntity.setUpdateUserid(null);
		dataModelEntity.setDeleted(null);
		return R.status(dataModelService.updateDataModel(dataModelEntity));
	}

	@RequestMapping("/deleteByIds")
	@ApiOperation("删除数据模型")
	@ApiOperationSupport(order = 4, includeParameters = "dataModelEntitiesIds.id")
	public R<DataModelEntity> deleteByIds(@Valid @RequestBody List<DataModelEntity> dataModelEntitiesIds){
		return R.status(dataModelService.deleteByIds(dataModelEntitiesIds));
	}

}
